package www.openteam.com.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;

/**
 * Created by kylin on 2017/4/14.
 */

public class OTScanView extends View {

    private Context context;
    private int mWidth, mHeight;

    public OTScanView(Context context) {
        super(context);

    }

    public OTScanView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }

    public OTScanView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, Context context1, int mWidth, int mHeight) {
        super(context, attrs, defStyleAttr);
        this.context = context1;
        this.mWidth = mWidth;
        this.mHeight = mHeight;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        //新建一个画笔
        Paint mPaint = new Paint();
        mPaint.setColor(Color.rgb(226,43,40));
        mPaint.setAntiAlias(true);
        mPaint.setStrokeWidth(fDp(5));

        int sY=mHeight*2/5;
        int sX=mWidth/10;

        //扫描界面四个角的线
        canvas.drawLine(0, 0, 0, fDp(18), mPaint);
        canvas.drawLine(0, 0, fDp(18), 0, mPaint);

        canvas.drawLine(0, mHeight - fDp(18), 0, mHeight, mPaint);
        canvas.drawLine(0, mHeight, fDp(18),mHeight,mPaint);

        canvas.drawLine(mWidth-fDp(18), 0, mWidth, 0, mPaint);
        canvas.drawLine(mWidth, 0, mWidth,fDp(18),mPaint);

        canvas.drawLine(mWidth, mHeight-fDp(18), mWidth, mHeight, mPaint);
        canvas.drawLine(mWidth-fDp(18), mHeight, mWidth,mHeight,mPaint);


    }


    public int fDp(float val) {

        return fTransDp(val);
    }

    private int fTransDp(float val) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, val,
                context.getResources().getDisplayMetrics());
    }


    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        //确定view大小
        mWidth = w;
        mHeight = h;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}
